package com.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wms.common.Result;
import com.wms.entity.Storage;
import com.wms.service.StorageService;
import com.wms.mapper.StorageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;

/**
 *
 */
@Service
public class StorageServiceImpl extends ServiceImpl<StorageMapper, Storage>
    implements StorageService {
  @Autowired
  StorageMapper storageMapper;
  @Autowired
  StorageService storageService;

  /**
   * 查询列表
   * @param storage
   * @param
   * @param
   * @return
   */
  @Override
  public Result list(Storage storage) {
    Page page=new Page<Storage>(storage.getPageNum(),storage.getPageSize());
    QueryWrapper<Storage> queryWrapper=new QueryWrapper<>();
    if(storage.getName()!=null&&!storage.getName().equals("")){
//      queryWrapper.eq("name", storage.getName());
      queryWrapper.like(StringUtils.isNotBlank(storage.getName()), "NAME", storage.getName());
    }
//    queryWrapper.eq("pageNum",storage.getPageNum());
//    queryWrapper.eq("pageSize",storage.getPageSize());
    IPage<Storage> list = storageService.pageMaps(page, queryWrapper);
    HashMap hashMap=new HashMap();
    hashMap.put("list", list.getRecords());
    Long aLong = storageMapper.selectCount(null);
    return Result.suc(hashMap,aLong);
  }

  @Override
  public Result insert(Storage storage) {
    int insert = storageMapper.insert(storage);
    return Result.suc(insert);
  }

  @Override
  public Result delete(int id) {
    QueryWrapper<Storage> queryWrapper=new QueryWrapper<>();
    queryWrapper.eq("id",id);
    int delete = storageMapper.delete(queryWrapper);
//    goodstypeMapper.delete(goodstype,queryWrapper);
    return Result.suc(delete);
  }

  @Override
  public Result select(Storage storage) {
    QueryWrapper<Storage> queryWrapper=new QueryWrapper<>();
    queryWrapper.eq("name", storage.getName());
    Storage storage1 = storageMapper.selectOne(queryWrapper);
    return Result.suc(storage1);
  }

  @Override
  public Result update(Storage storage) {
    QueryWrapper<Storage> queryWrapper=new QueryWrapper<>();
    queryWrapper.eq("id",storage.getId());
    int update = storageMapper.update(storage, queryWrapper);
    return Result.suc(update);
  }
}




